package com.ad.pet.common.structure.ui.activity;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.MenuItem;
import android.view.View;

import com.ad.pet.R;
import com.ad.pet.common.structure.ui.control.AppToolbar;
import com.githang.statusbar.StatusBarCompat;


/**
 * Created by z on.
 * Des:带有进度条
 * Date: 2017/3/8
 */

public abstract class AppToolbarActivity extends LoadingActivity {

    protected AppToolbar mToolbar;

    @Override
    protected int layoutResId() {
        return R.layout.activity_apptoolbar;
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mToolbar = (AppToolbar) findViewById(R.id.toolbar);
        initToolbar();
        init(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
        }
//        translucentStatus();
    }

    private void initToolbar() {
        mToolbar.setTitleTextColor(mActivity.getResources().getColor(R.color.white));
        mToolbar.setBackOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
            }
        });
        setSupportActionBar(mToolbar);
    }

    protected void init(Bundle savedInstanceState) {
    }
//    protected void setToolbar(Toolbar toolbar) {
//        setSupportActionBar(toolbar);
//        ActionBar bar =
//                getSupportActionBar();
//        bar.setDisplayHomeAsUpEnabled(true);
//        bar.setHomeButtonEnabled(true);
//    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int itemId = item.getItemId();
        if (itemId == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    protected void setToolbarNext(String text, View.OnClickListener listener) {
        mToolbar.setNextText(text);
        mToolbar.setNextOnClickListener(listener);

    }

    protected void hideRigth() {
        mToolbar.hideRigth();

    }

    protected void setLeftEnabled() {
        mToolbar.setLeftEnabled();
        mToolbar.isDispayBackIcon(false);
    }

    protected void setLeftVisable() {
        mToolbar.setLeftEnabled();
        mToolbar.isDispayBackIcon(true);
    }

    protected void setToolbarNext(View.OnClickListener listener) {
        mToolbar.setNextOnClickListener(listener);

    }

    protected String title() {
        return getString(R.string.title);
    }


    public void setToolbarNext(String text) {
        mToolbar.setNextText(text);
    }

    protected void setToolbarTitle(String title) {
        if (mToolbar == null) return;
        mToolbar.setTitle(title);
    }

    protected void close() {
        finish();
    }

    protected void translucentStatus() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            StatusBarCompat.setStatusBarColor(this, Color.parseColor("#0F0F33"), false);
        }

//            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//                StatusBarCompat.setStatusBarColor(this, Color.parseColor("#2E2C3A"), false);
    }
}


